<template>
  <div class="main-container">
    <div class="main-container__left">
      <div class="main-container__left--header">
        <el-input
          class="header-search"
          placeholder="搜索"
          v-model="form.search"
          clearable
          size="mini">
          <i slot="prefix" class="el-input__icon el-icon-search"></i>
        </el-input>
        <div class="header-btn">
          <i class="el-icon-plus"></i>
        </div>
      </div>
      <div class="main-container__left--body">
        <el-scrollbar class="scrollbar">
          <book-list :currentId="currentFriend.id" :source="bookList" @choose="handleChooseFriend"></book-list>
        </el-scrollbar>
      </div>
    </div>
    <div class="main-container__right">
      <el-avatar
        shape="square"
        :size="138"
        :src="currentFriend.avatar">
      </el-avatar>
      <span class="item-name">{{ currentFriend.nickname }}</span>
      <el-button class="item-btn" type="success" @click="sendMessage">发送消息</el-button>
    </div>
  </div>
</template>

<script>
import { mapActions, mapGetters } from 'vuex'
import BookList from '@/components/bookList'
export default {
  data () {
    return {
      form: {
        search: ''
      },
      currentFriend: {},
      bookList: [
        {
          groupTitle: 'A',
          friendList: [
            {
              id: 1,
              avatar: require('../../assets/images/avatar.jpg'),
              nickname: 'A123'
            },
            {
              id: 2,
              avatar: require('../../assets/images/avatar.jpg'),
              nickname: 'A456'
            },
            {
              id: 3,
              avatar: require('../../assets/images/avatar.jpg'),
              nickname: 'A789'
            }
          ]
        },
        {
          groupTitle: 'B',
          friendList: [
            {
              id: 4,
              avatar: require('../../assets/images/avatar.jpg'),
              nickname: 'B123'
            },
            {
              id: 5,
              avatar: require('../../assets/images/avatar.jpg'),
              nickname: 'B456'
            },
            {
              id: 6,
              avatar: require('../../assets/images/avatar.jpg'),
              nickname: 'B789'
            }
          ]
        }
      ]
    }
  },
  computed: {
    ...mapGetters(['chatList'])
  },
  components: {
    BookList
  },
  methods: {
    ...mapActions(['AddChatList']),
    handleChooseFriend (friend) {
      this.currentFriend = friend
    },
    sendMessage () {
      if (!this.currentFriend.id) {
        this.$message({
          message: '请先选择一个好友',
          type: 'warning'
        })
        return
      }
      this.$router.push({
        path: '/message'
      })
      this.AddChatList(this.currentFriend)
    }
  }
}
</script>

<style lang="less" scoped>
  .main-container__right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .item-name {
      padding: 20px 0;
    }
    .item-btn {
      width: 280px;
    }
  }
</style>
